home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 15 / CU Amiga Magazine's Super CD-ROM 15 (1997)(EMAP Images)(GB)[!][issue 1997-10].iso / CUCD / Graphics / Gallery / Source / PictureWindow.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-07-15  |  4.2 KB  |  184 lines

  1. #include <stream.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5. #include <stdio.h>
  6.  
  7. #include "GUICINCLUDE:GUIC_Screen.hpp"
  8. #include "GUICINCLUDE:GUIC_Application.hpp"
  9. #include "GUICINCLUDE:GUIC_GGFXPicture.hpp"
  10. #include "GUICINCLUDE:GUIC_Text.hpp"
  11. #include "GUICINCLUDE:GUIC_Number.hpp"
  12. #include "GUICINCLUDE:GUIC_StringType.hpp"
  13. #include "GUICINCLUDE:GUIC_Exceptions.hpp"
  14. #include "GUICINCLUDE:GUIC_BorderProp.hpp"
  15.  
  16. #include "PictureWindow.hpp"
  17.  
  18. /*********************************************************************************************************/
  19.  
  20. PictureWindowC::PictureWindowC        (GUIC_ApplicationC &app, GUIC_ScreenC &screen) : GUIC_WindowC (-1,-1,20,20)
  21. {
  22.     this->app         = &app;
  23.     this->screen    = &screen;
  24.     this->picture    = 0;
  25.     this->scale        = TRUE;
  26.     this->center     = TRUE;
  27.     
  28.     rightProp        = new GUIC_BorderPropC (GUIC_Vertical);
  29.     bottomProp    = new GUIC_BorderPropC (GUIC_Horizontal);
  30.     
  31.     add ( rightProp );
  32.     add ( bottomProp );
  33.     
  34.     widthGadget    = 0;
  35.     heightGadget    = 0;
  36.     textGadget        = 0;
  37.     
  38.     app.addPrefs("PictureWindow",    this);
  39.  
  40.     setCloseGadgetMode    ( FALSE );
  41.     setSizeable                    (GUIC_RightAndBottomBorder);
  42.     
  43.     setGuideContext("PictureWindow");
  44.     setTitle ( "Picture" );
  45. }
  46. PictureWindowC::~PictureWindowC        (VOID)
  47. {
  48.     cleanUp();
  49. }
  50.  
  51. /*********************************************************************************************************/
  52.  
  53. VOID                                PictureWindowC::setTextGadget            (GUIC_TextC *t)
  54. {
  55.     textGadget = t;
  56. }
  57. VOID                                PictureWindowC::setNumberGadgets    (GUIC_NumberC *n1, GUIC_NumberC *n2)
  58. {
  59.     widthGadget    = n1;
  60.     heightGadget    = n2;
  61. }
  62.  
  63. VOID                                PictureWindowC::setDimensions            (LONG x, LONG y)
  64. {
  65.     width = x;
  66.     height = y;
  67.     
  68.     setPixelWidth (x);
  69.     setPixelHeight (y);
  70. }
  71. VOID                                PictureWindowC::showPicture            (STRPTR fileName)
  72. {
  73.     if (picture) 
  74.         {
  75.         remove (picture);
  76.         delete picture; picture=0;
  77.         
  78.         if (widthGadget)        widthGadget    -> set ( 0 );
  79.         if (heightGadget)    heightGadget    -> set ( 0 );
  80.         }
  81.     
  82.     if (strcmp(fileName, "")) // else we should only close the picture
  83.         {
  84.         try
  85.             {
  86.             STRING m = "Loading picture: "; m+=fileName;
  87.     
  88.             if (textGadget)         textGadget        -> set ( m );
  89.             picture = new GUIC_GGFXPictureC (fileName);
  90.             if (widthGadget)        widthGadget    -> set ( picture->getWidth() );
  91.             if (heightGadget)    heightGadget    -> set ( picture->getHeight() );
  92.         
  93.             m = "Showing picture: "; m+=fileName;
  94.             if (textGadget)     textGadget -> set ( m );
  95.             if (center)            picture->setCentered(TRUE);
  96.             if (scale)             picture->setScaled(TRUE);
  97.             add (picture);
  98.             
  99.             rightProp->set ( 0, picture->getHeight(), picture->getVisibleY() );
  100.             bottomProp->set ( 0, picture->getWidth(), picture->getVisibleX() );
  101.             
  102.             }
  103.         catch (GUIC_Exception &e)
  104.             {
  105.             if (picture) { remove(picture); delete picture; picture = 0; }
  106.             STRING s = "Could not load picture: "; s+=fileName;
  107.             if (textGadget)         textGadget        -> set ( s );
  108.             rightProp->set(0,100,100);
  109.             bottomProp->set(0,100,100);
  110.             }
  111.         }
  112. }
  113.  
  114. VOID                                PictureWindowC::setScaled                (BOOL x)
  115. {
  116.     scale = x;
  117. }
  118. VOID                                PictureWindowC::setCentered                (BOOL x)
  119. {
  120.     center = x;
  121. }
  122.  
  123. STRPTR                            PictureWindowC::getClass                    (VOID)
  124. {
  125.     return "PictureWindowC";
  126. }
  127. GUIC_GGFXPictureC *    PictureWindowC::getPicture                (VOID)
  128. {
  129.     return picture;
  130. }
  131.  
  132. BOOL                                PictureWindowC::action                        (GUIC_EventC &e)
  133. {
  134.     switch (e.id)
  135.         {
  136.         case GUIC_GadgetEvent:
  137.             if (e.gadget == (GUIC_GadgetC *)rightProp)
  138.                 {
  139.                 if (picture) picture->setOffsetY(rightProp->getTop());
  140.                 return TRUE;
  141.                 }
  142.             else if (e.gadget == (GUIC_GadgetC *)bottomProp) 
  143.                 {
  144.                 if (picture) picture->setOffsetX(bottomProp->getTop());
  145.                 return TRUE;
  146.                 }
  147.             break;
  148.         case GUIC_WindowResize:
  149.             if (picture)
  150.                 {
  151.                 picture->setOffsets(0,0);
  152.                 rightProp->set ( 0, picture->getHeight(), picture->getVisibleY() );
  153.                 bottomProp->set ( 0, picture->getWidth(), picture->getVisibleX() );
  154.                 }
  155.             return TRUE;
  156.             break;
  157.         case GUIC_OpenWindow:
  158.             return TRUE;
  159.             break;
  160.         case GUIC_CloseWindow: 
  161.             return FALSE;
  162.             break;
  163.         default:
  164.             cerr << "PictureWindow got an event: " << e.id << endl;
  165.         }
  166.     
  167.     return FALSE;
  168. }
  169.  
  170. /*********************************************************************************************************/
  171.  
  172. VOID                                 PictureWindowC::cleanUp                    (VOID)
  173. {    
  174.     if (picture)
  175.         {
  176.         remove (picture);
  177.         delete picture;
  178.         }
  179.         
  180.     delete rightProp;
  181.     delete bottomProp;
  182. }
  183.  
  184.